//
//  ZNBPresentingAnimator.m
//  ZNB
//
//  Created by znb_iOS on 16/7/28.
//  Copyright © 2016年 znb. All rights reserved.
//

#import "ZNBPresentAnimator.h"

@interface ZNBPresentAnimator ()

@end

@implementation ZNBPresentAnimator

- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext {
    return 0.5;
}

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
    UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    CGRect finalFrame = [transitionContext finalFrameForViewController:toVC];
    CGSize screenSize = [UIScreen mainScreen].bounds.size;
    toVC.view.frame = CGRectMake(screenSize.width, finalFrame.origin.y, finalFrame.size.width, finalFrame.size.height);
    [[transitionContext containerView] addSubview:toVC.view];
    NSTimeInterval duration = [self transitionDuration:transitionContext];
    
    [UIView animateWithDuration:duration delay:0 usingSpringWithDamping:1.0 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        toVC.view.frame = finalFrame;
        fromVC.view.transform = CGAffineTransformMakeTranslation(-100, 0);
    } completion:^(BOOL finished) {
        fromVC.view.transform = CGAffineTransformIdentity;
        [transitionContext completeTransition:!transitionContext.transitionWasCancelled];
    }];
    
}
@end
